package myPack.GMAO.Bean;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import myPack.GMAO.Entity.Piece;
import myPack.GMAO.Interface.PieceInterface;

@Stateless
public class PieceBean implements PieceInterface {
	
	@PersistenceContext
	EntityManager em;
	
	@Override
	public void ajoter(Piece p) {
		em.merge(p);
	}

	@Override
	public void supprimer(int idP) {
		em.remove(em.find(Piece.class, idP));
	}

	@Override
	public Piece chercher(int idP) {
		
		return em.find(Piece.class, idP);
	}

	@Override
	public List<Piece> lister() {
		return em.createQuery("from Piece").getResultList();
	}

}
